﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using FluentValidation;
using FluentValidation.Attributes;
using PicStore.Common;

namespace PicStore.Web.Models.Apply
{
    [Serializable]
    [Validator(typeof(AddRequestModelValidator))]
    public class AddRequestModel
    {
        public string Error { get; set; }

        [Display(Name = "Request User Name")]
        public string RequestUserName { get; set; }

        [Display(Name = "Department")]
        public string Department { get; set; }

        [Display(Name = "Phone")]
        public string Phone { get; set; }

        [Display(Name = "Mobile")]
        public string Mobile { get; set; }

        [Display(Name = "Project")]
        public string Project { get; set; }

        [Display(Name = "Leader Name")]
        public string LeaderName { get; set; }

        [Display(Name = "Apply Date")]
        public DateTime CreateTime { get; set; }

        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }

        [Display(Name = "Sex")]
        public List<System.Web.Mvc.SelectListItem> SexList { get; set; }

        [Display(Name = "Place")]
        public List<System.Web.Mvc.SelectListItem> PlaceList { get; set; }

        [Display(Name = "Need Download Picture")]
        public bool NeedDownloadPicture { get; set; }

        [Display(Name = "Description")]
        public string Description { get; set; }

        [Display(Name = "Comments")]
        public string Comments { get; set; }
    }

    public class AddRequestModelValidator : AbstractValidator<AddRequestModel>
    {
        public AddRequestModelValidator()
        {
            RuleFor(x => x.Department).NotNull().WithMessage(string.Format(Constants.MustInput, "Department"));
            RuleFor(x => x.Phone).NotNull().WithMessage(string.Format(Constants.MustInput, "Phone"));
            RuleFor(x => x.Mobile).NotNull().WithMessage(string.Format(Constants.MustInput, "Mobile"));
            RuleFor(x => x.StartDate).NotNull().WithMessage(string.Format(Constants.MustInput, "Start Date"));
            RuleFor(x => x.EndDate).NotNull().WithMessage(string.Format(Constants.MustInput, "End Date"));
            RuleFor(x => x.EndDate).LessThan(x => x.StartDate).WithMessage(string.Format("Start date must not be greater than the end date"));
        }
    }
}